/*
版本信息: 201807252303
*/
var G = {};
G.list =[];

/*-----------------------------PC端文件导入及预览控制方法----------------------------------*/

//页面加载初始化,在 onload 执行
function init(){
    G.errList = [];//错题列表，初始化为空列表
    G.currentIndex = 0;//G.currentIndex 作为 G.currentList 的索引
    G.InTest = false;//考试状态重置为否
    getEbyId("input_ImportFromFile").value="";
    lock("btn_Import",true);//锁定导入按钮
    G.timer=null;//计时器引用，必须只初始化为null一次
    examInit1();
    G.comboStr=["","","连对两题","大做特做","主宰考场","做题如麻","叹为观止","无题能挡","学霸附体","学神你好","超越神"];
}

//初始化1，每次导入题库都要初始化
function examInit1(){
    
    // 计时器变量初始化
    G.Hour = 0;
    G.Minute = 0;
    G.Second = 0;
    G.list=[];
    /*导入前初始化*/
    G.quesData=new Array();//保存 类型编号 - 名称,该类型总计数,该类型已完成数
    G.quesData[0]=["无效",0 , 0];
    G.quesData[1]=["单选",0 , 0];
    G.quesData[2]=["多选",0 , 0];
    G.quesData[3]=["判断",0 , 0];
    G.quesData[4]=["不定项",0 , 0];
    G.quesData[5]=["填空",0 , 0];
    G.quesData[6]=["排序",0 , 0];
    G.quesData[7]=["论述",0 , 0];
    G.quesData[8]=["简答",0 , 0];
    G.quesData[9]=["案例",0 , 0];
    switchOptColMode();
    checkooo();
    checkNextQ();
    checkEffects();
    G.create_importFileType=["xlsx","xls"];
    G.quecol = getVbyId("input_quecol");//题目对应列的数字编号
    G.typecol = getVbyId("input_typecol");//类型对应列的数字编号
    G.optcol0 =getVbyId("input_optcol0");//选项对应列的数字编号0
    G.optcol1 = getVbyId("input_optcol1");//选项对应列的数字编号1
    G.optdelim = getVbyId("input_delim");//分隔符
    G.anscol = getVbyId("input_anscol");//答案对应列的数字编号
    G.expcol = getVbyId("input_expcol");//解释对应列的数字编号
    
    G.all = []; //all仅为序号列表，初始化时将list中所有题对应的序号加入
    G.allListIndex = 0;//全部题列表的索引
    G.errListIndex = 0;//错题列表的当前索引
    G.currentList = G.all;//currentList用于 在 全部试题 和 错题 的序号列表之间切换
    G.Combo = 0;
    G.lastComboIndex = -1;
    
    //生成随机排序列表；randomlist用于按顺序存储当前显示选项的原始编号；flaglist用于存储答案原始编号是否已放入randomlist的标志；   ansidlist存放原始编号对应的选项编号。chosedlist保存原始编号是否被选择。每次showQues前，遍历一次randomlist、ansidlist、chosedlist,全置为0或false-->
    G.choicelistlength = 10;
    G.randomlist = new Array(G.choicelistlength);
    G.flaglist = new Array(G.choicelistlength);
    G.ansidlist = new Array(G.choicelistlength);
    G.chosedlist = new Array(G.choicelistlength);
    G.currentoptioncount=0;
}

//导入后初始化
function examInit2(){
    getEbyId("btnShowAll").innerHTML="全部(W) "+G.list.length.toString()+"题";
    //终止现有 timer
    if(G.timer!=null){
        window.clearInterval(G.timer);
    }
  //设置调用UpdateTime的时间间隔为1000毫秒-->
    G.timer=window.setInterval(UpdateTime,1000);
    showQues();
    getEbyId("Ans").disabled = true;
    getEbyId("divChoice").disabled=true;
}

//切换选项所在列模式
function switchOptColMode(){
    if(getEbyId("input_optMode0").checked){//如果是单列模式
        G.optCols=0;//列数量模式=0
        getEbyId("label_optEnd").style.display="none";//隐藏多列的末列标签
        getEbyId("input_optcol1").style.display="none";//隐藏多列的末列输入框
        getEbyId("label_delim").style.display="";//显示分隔符标签
        getEbyId("input_delim").style.display="";//显示分隔符输入框
    }
    else{//如果是多列模式
        G.optCols=1;//列数量模式=1
        getEbyId("label_optEnd").style.display="";//隐藏多列的末列标签
        getEbyId("input_optcol1").style.display="";//显示多列的末列输入框
        getEbyId("label_delim").style.display="none";//显示分隔符标签
        getEbyId("input_delim").style.display="none";//隐藏分隔符输入框
    }
}


//特效显示
function showEffects(){
    for(var i=1;i<G.quesData.length;i++){
        var iStr=i.toString();
        var div_b=getEbyId("b_"+iStr);//为当前题型更新进度条div
        if(G.quesData[i][1]>0){
            var ti=Math.floor(G.quesData[i][1]*100/G.list.length);
            var tif=Math.floor(G.quesData[i][2]*100/G.quesData[i][1]);
            div_b.style.width=ti.toString()+"%";
            var div_b0=getEbyId("b_"+iStr+"_0");//为当前题型的已完成部分创建进度条div
            div_b0.style.width=tif.toString()+"%";
        }
        else{
            div_b.style.display="none";
        }
    }
    if(G.Combo>1){//combo文字特效
        var lbl = getEbyId("label_combo");
        $("#label_combo").text((G.Combo<=10)?G.comboStr[G.Combo]:G.comboStr[10]);//文本内容更新
        lbl.style.fontSize=(G.Combo<=10)?(G.Combo*0.5+5).toString()+"em":"10em";//字号更新
        lbl.style.fontWeight=(G.Combo<=9)?(G.Combo*50+300).toString():"750";//字体加粗程度更新
        lbl.style.color=randomColor();
        lbl.style.zIndex="10";
        var v_opacity=1.0;
        var rv=self.setInterval(function(){
            if(v_opacity>0){
                lbl.style.opacity=v_opacity.toString();
                v_opacity-=0.02;
            }
            else{
                lbl.style.zIndex="-1";
                lbl.innerHTML="";
                window.clearInterval(rv);
            }
        },100+(G.Combo<=10)?G.Combo*2:120);
    }    
}

//随机颜色
function randomColor(){
    var color="#";
    for(var j=0;j<6;j++){
        var v=Math.floor(Math.random()*16,16);
        color+=(v<10)?v.toString():String.fromCharCode(v+55);
    }
    return color;
}

//特效开关
function checkEffects(){
    G.effects=getEbyId("cb_effects").checked;
    if(G.effects){//如果打开特效，需要事先指定的数据在这里配置
    
    //进度条配置，需要已经载入问题数据
        if( typeof(G.quesData)=="object" && typeof(G.quesData.length)=="number"){
        
            getEbyId("div_4").style.display="";
            for(var i=1;i<G.quesData.length;i++){
                getEbyId("b_"+i.toString()+"_0").style.backgroundColor=randomColor();
            }
        }else{
            getEbyId("div_4").style.display="none";//进度条：隐藏
        }
    }
    else{
    getEbyId("div_4").style.display="none";//进度条：隐藏
    }
}

//乱序开关
function checkooo(){
    G.ooo=getEbyId("cb_ooo").checked;
}

//自动下一题开关
function checkNextQ(){
    G.nextQ=getEbyId("cb_NextQ").checked;
}


//识别文件格式以及sheet 名单
function readFile(){
    var selectObj = getEbyId("select_ChooseSheet");//获得选项框
    var file = getEbyId("input_ImportFromFile").files[0];//获得文件
    var filename = file.name;//获得文件名
    
    if(!filename || filename==""){return;}
    //拆分文件名得到类型
    var namesplit = filename.split(".");
    var namelen = namesplit.length;
    var type = "无法识别";
    if(namelen>1){
        type = namesplit[ namesplit.length -1 ];//更新目标文件类型
        getEbyId("label_ImportFileType").innerHTML = type;
        if( wordInArray(type , G.create_importFileType)>=0 ){
            selectObj.options.length = 0;//清空选项
            var fileReader = new FileReader();
            switch (type){//根据类型，进行处理
            case "xls":
                fileReader.onload = function(event){
                    var res = event.target.result;
                    var cfb = XLS.CFB.read(res, {type: 'binary'});
                    G.workbook = XLS.parse_xlscfb(cfb);
                    var count = 0;
                    for(var sheetname in G.workbook.Sheets){
                        if (G.workbook.Sheets.hasOwnProperty(sheetname)) {
                            selectObj.options.add(new Option(sheetname,sheetname) );//在 表名选择栏添加表名
                            count+=1;
                        }
                        if( count >= G.workbook.SheetNames.length){
                            preview(G.workbook);
                            }//如果表格遍历完成，预览表头
                    }
                };
                fileReader.readAsBinaryString(file);//读取文件
                break;
            case "xlsx":
                fileReader.onload=function(event){
                    var res = event.target.result;
                    G.workbook = XLSX.read( res , {type:"binary"} );
                    var count = 0;
                    for(var sheetname in G.workbook.Sheets){//对每个 sheet
                        if (G.workbook.Sheets.hasOwnProperty(sheetname)) {
                            selectObj.options.add(new Option(sheetname,sheetname) );//在 表名选择栏添加表名
                            count+=1;
                        }
                        if( count >= G.workbook.SheetNames.length){
                            preview(G.workbook);
                            }//如果表格遍历完成，预览表头
                    }
                };
                fileReader.readAsBinaryString(file);//读取文件
                break;
            case "csv":case "txt":
                
                break;
            }
        }
    }
    if(getVbyId("input_ImportFromFile")!=""){lock("btn_Import",false);}//如果没选择导入文件，锁定按钮
}

//更新文件读取元数据
function updateMetaData(){
    //更新各列对应编号
    G.quecol = getVbyId("input_quecol");
    G.typecol = getVbyId("input_typecol");
    G.optcol0 = getVbyId("input_optcol0");
    G.optcol1 = getVbyId("input_optcol1");
    G.optdelim = getVbyId("input_delim");
    G.anscol = getVbyId("input_anscol");
    G.expcol = getVbyId("input_expcol");
}

//从 G.workbook 中导入预览数据进行展示
function preview(){
    updateMetaData();
    var type = getEbyId("label_ImportFileType").innerHTML;//获取文件扩展名
    var objSelect = getEbyId("select_ChooseSheet");//获得sheet选择器
    var sheetname = objSelect.options[objSelect.selectedIndex].text;//获得 sheet 名
    G.sheetname=sheetname;
    var rowStr = getVbyId("input_startRow").toString();//获得当前目标行
    switch(type){
    default:
        break;
    case "xlsx":case "xls":
        if(!G.workbook){readFile();}
        var sheet = G.workbook.Sheets[sheetname];//获得目标 sheet
        getEbyId("td_que").innerHTML=(sheet[G.quecol+rowStr] && sheet[G.quecol+rowStr].v)?sheet[G.quecol+rowStr].v:"";
        getEbyId("td_type").innerHTML=(sheet[G.typecol+rowStr] && sheet[G.typecol+rowStr].v)?sheet[G.typecol+rowStr].v:"";
        getEbyId("td_ans").innerHTML=(sheet[G.anscol+rowStr] && sheet[G.anscol+rowStr].v)?sheet[G.anscol+rowStr].v:"";
        getEbyId("td_exp").innerHTML=(sheet[G.expcol+rowStr] && sheet[G.expcol+rowStr].v)?sheet[G.expcol+rowStr].v:"";
        
        var opts = [];//选项填入数组
        if(G.optCols==0){//如果是单列选项，进行切分；此时所有选项在 que["o0"]
            opts=( (sheet[G.optcol0+rowStr].v)?sheet[G.optcol0+rowStr].v:"").split(G.optdelim);
        }
        else{//如果是多列选项，从开始列到结束列逐个填入que["opt"]
            var startCol = getCol_StrToNum(G.optcol0);//起始列转数字
            var endCol = getCol_StrToNum(G.optcol1);//终结列转数字
            if(startCol > endCol){
                var tmp = startCol;
                startCol = endCol;
                endCol = tmp;
            }
            for(var i=startCol;i<=endCol;i++){
                opts.push( (sheet[getCol_numToStr(i)+rowStr] && sheet[getCol_numToStr(i)+rowStr].v)?sheet[getCol_numToStr(i)+rowStr].v:"" );
            }
        }
        //选项填入预览表格
        getEbyId("td_opt").innerHTML=opts.join("<br>");
        break;
    }
}

//导入至题库
function importData(){
    examInit1();
    //如果是在做题状态，改为暂停状态，并且重置时间
    if(G.InTest==true){PauseTest();getEbyId("Timer").innerHTML="00:00:00";}
    //更新各列对应编号
    updateMetaData();
    var type = getEbyId("label_ImportFileType").innerHTML;//获取文件扩展名
    var objSelect = getEbyId("select_ChooseSheet");//获得sheet选择器
    var sheetname = objSelect.options[objSelect.selectedIndex].text;//获得 sheet 名
    var startRow = parseInt(getVbyId("input_startRow"));//获得当前目标行
    switch(type){
    default:
        break;
    case "xlsx":case "xls":
        if(!G.workbook){readFile();}
        var sheet = G.workbook.Sheets[sheetname];//获得目标 sheet
        var bound = sheet["!ref"].split(":");//边界字符串数组，[0]为左上角单元格坐标，[1]为右下角单元格坐标
        var cor0=parseRow_Col( bound[0] );//获得左上角坐标
        var cor1=parseRow_Col( bound[1] );//获得右下角坐标
        
        var row = startRow;
        while(row <=cor1[0]){
            var rowStr = row.toString();
            var Q={};
            var que=(sheet[G.quecol+rowStr] && sheet[G.quecol+rowStr].v)?sheet[G.quecol+rowStr].v:"";//Ques
            var tStr=(sheet[G.typecol+rowStr] && sheet[G.typecol+rowStr].v)?sheet[G.typecol+rowStr].v:"";//类型
            if(tStr.indexOf("单选")>=0){Q["type"]=1;}
            else if(tStr.indexOf("多选")>=0){Q["type"]=2;}
            else if(tStr.indexOf("判断")>=0){Q["type"]=3;}
            else if(tStr.indexOf("不定项")>=0){Q["type"]=4;}
            else if(tStr.indexOf("填空")>=0){Q["type"]=5;}
            else if(tStr.indexOf("排序")>=0){Q["type"]=6;}
            else if(tStr.indexOf("论述")>=0){Q["type"]=7;}
            else if(tStr.indexOf("简答")>=0){Q["type"]=8;}
            else if(tStr.indexOf("案例")>=0){Q["type"]=9;}
            else{Q["type"]=0;}
            // 在 G.quesData 更新数据
            G.quesData[Q["type"]][1]+=1;
            //处理选项
            if(Q["type"]==1 || Q["type"]==2 || Q["type"]==4){
                var opts = [];//选项数组
                if(G.optCols==0){//如果是单列选项，进行切分；此时所有选项在 que["o0"]
                    opts=( (sheet[G.optcol0+rowStr].v)?sheet[G.optcol0+rowStr].v:"").split(G.optdelim);
                }
                else{//如果是多列选项，从开始列到结束列逐个填入que["opt"]
                    var startCol = getCol_StrToNum(G.optcol0);//起始列转数字
                    var endCol = getCol_StrToNum(G.optcol1);//终结列转数字
                    
                    // 起始-终结如果大小相反，先对换
                    if(startCol > endCol){
                        var tmp = startCol;
                        startCol = endCol;
                        endCol = tmp;
                    }
                    
                    // startCol,endCol 越界处理
                    if (startCol < cor0[1] || startCol > cor1[1]){ startCol=cor0[1];}
                    if (endCol < cor0[1] || endCol > cor1[1]){endCol=cor1[1];}
                    
                    
                    for(var i=startCol;i<=endCol;i++){
                        //如果单元格内有文字，则认为是有效选项放入
                        if(sheet[getCol_numToStr(i)+rowStr] && sheet[getCol_numToStr(i)+rowStr].v && sheet[getCol_numToStr(i)+rowStr].v.toString()!=""){
                            opts.push(sheet[getCol_numToStr(i)+rowStr].v);
                        }
                    }
                }
                Q["Ques"]=que+"\t"+opts.join("\t");
            }
            else{Q["Ques"]=que;}
            
            //答案处理
            var aStr=(sheet[G.anscol+rowStr] && sheet[G.anscol+rowStr].v)?sheet[G.anscol+rowStr].v:"";
            //如果是选择题
            if(Q["type"]<=4){
                //删除空格
                aStr = aStr.replace(" ","");
                //对答案字符串逐个处理
                Q["ans"]=new Array();
                for(var i=0;i<aStr.length;i++){
                    Q["ans"].push(aStr.charCodeAt(i)-64);
                }
            }
            //如果是填空 论述 简答 案例
            else if(Q["type"]==5||Q["type"]==7||Q["type"]==8 ||Q["type"]==9){
                Q["ans"] = aStr;
            }
            
            //处理 解释
            Q["explain"]=(sheet[G.expcol+rowStr] && sheet[G.expcol+rowStr].v)?sheet[G.expcol+rowStr].v:"";
            
            
            G.list.push(Q);
            G.all.push([row-startRow,false]);
            row+=1;
        }
        break;
    }
    examInit2();
}


//读取本地错题
function loadErrors(){
    G.errList = [];//初始化错题列表为空列表
    G.currentIndex = 0;//G.currentIndex 作为 G.currentList 的索引
    var file=getEbyId("input_ErrorQues").files[0];//获得错题本文件
    if (window.ActiveXObject){//如果当前使用IE浏览器
        var fso = new ActiveXObject("Scripting.FileSystemObject"); 
        var errorfile = fso.opentextfile(file.name,true);
        var errlist=errorfile.ReadAll().split(" ");
        //对 errlist 以空格拆分
        for(var i=0;i<errlist.length;i++){
            Number(errlist[i])-1>=0?G.errList.push([Number(errlist[i])-1,false]):null;
        }
        G.errList.length>0?Message("成功导入"+G.errList.length.toString()+"道错题","green"):Message("未导入错题","red");
    }
    else{//非 IE 浏览器
        if(typeof(FileReader) == "undefined"){
            Message("浏览器不支持文件读取","red");
        }
        else{
            reader = new FileReader();
            reader.onload=function(event){
                errlist = event.target.result.split(" ");
                //对 errlist 以空格拆分
                for(var i=0;i<errlist.length;i++){
                    if(Number(errlist[i])-1>=0){
                      G.errList.push([Number(errlist[i])-1,false]);
                    }
                }
                G.errList.length>0?Message("成功导入"+G.errList.length.toString()+"道错题","green"):Message("未导入错题","red");
            };
            reader.readAsText(file);
        }
    }
    
}

/*-------------------------------考试控制--------------------------------------*/

function showQues()//展示问题
{
    if(G.InTest==true)
    {
        // 判断当前索引是全部题目还是错题本
        if(G.currentList==G.all){ G.allListIndex = G.currentIndex; }
        else{ G.errListIndex = G.currentIndex; }
        
        //如果当前列表无题目
        if(G.currentList.length<=0){return;}
        
        //初始化消息
        Message("","red");
        getEbyId("divAns").innerHTML = "";
        getEbyId("Ans").disabled = false;
        
        var parts = G.list[G.currentList[G.currentIndex][0]]["Ques"].split("\t");
        var question = parts[0];
        var ty=G.list[G.currentList[G.currentIndex][0]].type;
        
        var tystr=". [未定义]"
        switch(ty){
            case 1:tystr=". [单选]";break;
            case 2:tystr=". [多选]";break;
            case 3:tystr=". [判断]";break;
            case 4:tystr=". [不定项]";break;
            case 5:tystr=". [天空]";break;
            case 6:tystr=". [排序]";break;
            case 7:tystr=". [论述]";break;
            case 8:tystr=". [简答]";break;
            case 9:tystr=". [案例]";break;
        }
        
        $("#divQues").text((G.currentList[G.currentIndex][0] + 1) + tystr + question);//试题内容
        if (ty==1||ty==2 ||ty==4 ||ty==6)
        {
            G.currentoptioncount = parts.length - 1;//重置randomlist和ognlist，用len控制当前题目所需要的长度
            if(G.ooo){//启用乱序
                for (var i = 0;i < G.choicelistlength;i+=1)//乱序前初始化
                {
                    G.randomlist[i]=G.choicelistlength;
                    G.flaglist[i] = false;
                    G.ansidlist[i] = 0;
                    G.chosedlist[i] = false;
                }
                var rdlstid = 0;
                while( rdlstid<G.currentoptioncount)//制造乱序
                {
                    var curNum = Math.floor(Math.random()*G.currentoptioncount);
                    if(curNum<G.currentoptioncount && G.flaglist[curNum]==false)
                    {
                        G.flaglist[curNum] = true;
                        G.ansidlist[curNum] = rdlstid;
                        G.randomlist[ rdlstid ]=curNum;
                        rdlstid+=1;
                    }
                }
            }
            else{//不启用乱序
                G.currentoptioncount = parts.length - 1;
                for (var i = 0;i < G.choicelistlength;i+=1)//乱序前初始化
                {
                    G.randomlist[i]=i;
                    G.flaglist[i] = true;
                    G.ansidlist[i] = i;
                    G.chosedlist[i] = true;
                }
            }
            
            var choice = getEbyId("divChoice");
            //按生成的随机顺序，排列选项
           
            if (ty == 1)//单选题
            {
                getEbyId("btnSubmit").disabled = true;//禁用提交按钮
                //choice.innerHTML = "";
                //清理原有选项
                $("#divChoice").empty();
                for (var i = 0; i < G.currentoptioncount; ++i)
                {
                    //创建元素
                    var curOpt = document.createElement("div");
                    //设置样式
                    curOpt.setAttribute("style","height:2em;width:100%;padding:0.5em 0em 0.5em 1em");
                    //添加元素
                    choice.appendChild(curOpt);
                    
                    //添加文本
                    var textnode=document.createElement("label");
                    textnode.innerHTML="("+String.fromCharCode(i+65)+")"+ parts[ G.randomlist[i]+1];
                    //设置点击事件
                    textnode.setAttribute("onclick","ansClicked(G.randomlist["+i.toString()+"])",true);
                    //增加节点
                    curOpt.appendChild(textnode);
                }
            }
            else
            {
                choice.innerHTML = "";
                for (var i = 0; i < G.currentoptioncount; ++i)
                {
                    choice.innerHTML += '<span onclick="ansClicked(' + G.randomlist[i] + ')"><label style="display:none;"></label><span id="Choice'+G.randomlist[i] +'">(' + String.fromCharCode(i+65)+')' + parts[ G.randomlist[i]+1 ] + "</span></span><br /><br/>";
                }
                if (ty == 2)//多选题
                {
                    getEbyId("btnSubmit").disabled = false;
                    
                }
                else if (ty== 4)//不定项
                {
                    getEbyId("btnSubmit").disabled = false;
                }
                else if (ty== 6)//排序题
                {
                    getEbyId("btnSubmit").disabled = false;
                    //生成排序框
                    choice.innerHTML+='<a id="fill_sort" style="width:300px" />';
                }
            }
        }
        
        else if (ty== 3)//判断题
        {
            G.currentoptioncount = 2;
            getEbyId("btnSubmit").disabled = true;
            var choice = getEbyId("divChoice");
            choice.innerHTML = "";
            choice.innerHTML += '<a href="#" onclick="ansClicked(0)">(A) 正确</a><br /><br/>';
            choice.innerHTML += '<a href="#" onclick="ansClicked(1)">(B) 错误</a><br /><br/>';
        }
        
        else if (ty== 5)//填空题
        {
            getEbyId("btnSubmit").disabled = false;//启用提交按钮
            var choice = getEbyId("divChoice");
            choice.innerHTML = "";//获得原有的选项区域，在这里生成文本输入框
            choice.innerHTML+='<input type="text" id="fill_empty" style="width:300px" />';
        }

        else if (ty== 7|| ty==8||ty==9)//论述 简答 案例
        {
            getEbyId("btnSubmit").disabled = true;
            var choice = getEbyId("divChoice");
            choice.innerHTML = "";//获得原有的选项区域，在这里生成文本输入框
            choice.innerHTML+='<input type="text" id="fill_essay" style="width:300px" />';
        }
    }
    else
    {
        getEbyId("Ans").disabled = true;
        getEbyId("divAns").innerHTML = "";
        getEbyId("divQues").innerHTML = " 暂停计时，请点击“开始”/“继续”按钮，继续测试 ";
        getEbyId("divChoice").innerHTML = "";
    }
}

function Message(msg,clr)//提示消息及颜色
{
        getEbyId("divNotes").innerHTML =msg;
        getEbyId("divNotes").style.color=clr;        
}
function ComboUpdate(value)//更新连对题计数
{
    if (value == true )
    {
        if( G.currentIndex > G.lastComboIndex )
        {
            G.Combo+=1;
            G.lastComboIndex = G.currentIndex;
        }
    }
    else{G.Combo=0;}
    document.title="Combo "+ G.Combo.toString();
}
function previous()//上一题
{
    if (G.currentIndex != 0)
    {
        Message("","white");
        G.currentIndex--;
        if(G.InTest==false)
        {
            PauseTest();
        }
        else
        {
            showQues();
        }
    }
    else 
    {
        Message("第一个了！","red");
    }
}
function next()//下一题
{
    if (G.currentIndex < G.currentList.length - 1)
    {
        Message("","white");
        G.currentIndex++;
        if(G.InTest==false)
        {
            PauseTest();
        }
        else
        {
            showQues();
        }
    }
    else 
    {
        Message("最后一个了！","red");
    }
}


//初始化随机列表相关数据结构
for (var i = 0;i < G.choicelistlength;i+=1)
{
    G.randomlist[i]=G.choicelistlength;
    G.flaglist[i]=false;
    G.ansidlist[i]=0;
    G.chosedlist[i]=false;
}


//生成错题序号的下载链接
function makeErrDownload()
{
    if( G.errList.length == 0)
    {
        Message("没有错题，啥都不给","gray");
        return;
    }
    else
    {
        var errlistStr="";
        for (var i = 0;i < G.errList.length;)//构造文本
        {
            errlistStr += (G.errList[i][0]+1).toString();//显示的题号 = 列表中的编号+1
            i+=1;
            if(i<G.errList.length)
            {errlistStr+=" ";}
        }
        var dllink='<a href="data:text/plain,'+errlistStr+'" download="ErrList.txt">点此下载错题</a>';//生成链接
        Message(dllink,"#FF0");//链接放入
    }
}

//添加index号到错题本-->
function addToErrList(index)
{
    var isFound = 0;
    for (var i = 0; i < G.errList.length; ++i)
    {
        if (G.errList[i][0] == index)
        {
            isFound = 1;
            break;
        }
    }
    if (isFound == 0)//未查找到，则更新错题本
    {
        // 插入的数据与all 格式相同，为二个元素的数组
        G.errList.push([index , false]);
        getEbyId("btnErrList").innerHTML = "错题本(Q) " + G.errList.length + " ";
    }
}

function showErrList()//切换至展示错题列表
{
    if (G.errList.length > 0) 
    {
        G.currentList = G.errList;
        G.currentIndex = G.errListIndex;
        showQues();
    }
    else{ Message("万无一失","green"); }
}

//展示所有试题-->
function showAll()
{
    if (G.all.length > 0) 
    {
        G.currentList = G.all;
        G.currentIndex = G.allListIndex;
        showQues();
    }
    else{Message("空无一物","green");}
}

//“提交”按钮的函数实现-->
function checkAns()
{
    var choice = getEbyId("divChoice");
    var choices = choice.children;
    var correct = false;
    var ty=G.list[G.currentList[G.currentIndex][0]].type;
    if (ty==2||ty==4)
    {//多选题，进行答案组装-->
        var ansValue = 0;
        var choicesValue = 0;
        var anslen = G.list[G.currentList[G.currentIndex][0]].ans.length;
        for (var i = 0;i<anslen;i++)//正确答案特征值计算
        {ansValue +=Math.pow(2, G.list[G.currentList[G.currentIndex][0]].ans[i]-1);}
        for (var i = 0; i < choices.length; i++)//选项特征值计算
        {
            if(G.randomlist[i]<G.chosedlist.length && G.chosedlist[ G.randomlist[i] ]==true)
            {
                choicesValue += Math.pow(2,G.randomlist[i]);
            }
        }
        if(ansValue == choicesValue)
        {correct = true;}
    }
    else if(ty==5)
    {//填空题，生成文本输入框，与答案比对-->
        var fill_ans = getEbyId("fill_empty").value ;
        var fill_ans_list = fill_ans.split(" ");//字符串分割
        //所有输入文字都在答案里才算正确
        var fill_correct_count=0;
        for(var i = 0;i<fill_ans_list.length;i++)
        {
            if( G.list[G.currentList[G.currentIndex][0]].ans[0].match( fill_ans_list[i] ) )
            {fill_correct_count+=1;}
            else
            {break;}
        }
        if( fill_correct_count == fill_ans_list.length)
        {correct = true;}
    }
    else if(ty==6)//排序题
    {
        var fill = getEbyId("fill_sort").text;
        if(fill.length != G.list[G.currentList[G.currentIndex][0]].ans.length)//长度判断，如果提交的数量与答案不一致则判为错
        {correct=false;}
        else
        {
            var ans_ptr = 0;
            for(var j = 0;j<fill.length && ans_ptr<G.list[G.currentList[G.currentIndex][0]].ans.length;j++)
            {
                if( fill[j] != String.fromCharCode( G.ansidlist[G.list[G.currentList[G.currentIndex][0]].ans[j]-1]+65 ) )
                {break;}
                else{ans_ptr+=1;}
            }
            if(ans_ptr == G.list[G.currentList[G.currentIndex][0]].ans.length){correct = true;}
        }
    }
    showAnsInfo(correct);
}

//点击选项的函数实现-->
function ansClicked(origin_id)
{
    var ty = G.list[G.currentList[G.currentIndex][0]].type;
    //多选题、不定项，将选项改为红色字样-->
    if (ty == 2 || ty == 4)
    {
        var curChoiceId = "Choice"+origin_id.toString();
        if (getEbyId(curChoiceId).style.color != "red")
        {
            getEbyId(curChoiceId).style.color = "red";
            G.chosedlist[origin_id]=true;
        }
        else 
        {
            getEbyId(curChoiceId).style.color = "black";
            G.chosedlist[origin_id]=false;
        }
    }
    else if (ty == 1)//单选题
    {showAnsInfo(G.list[G.currentList[G.currentIndex][0]].ans[0] == origin_id+1);}
    else if(ty == 3){showAnsInfo(G.list[G.currentList[G.currentIndex][0]].ans[0] == origin_id+1);}
    else if(ty == 6)//排序题，将字母填入输入框中
    {getEbyId("fill_sort").innerHTML+=String.fromCharCode( G.ansidlist[origin_id]+65);}
}

//显示回答的判定信息-->
function showAnsInfo(flag)
{
    if(G.currentList==G.all && G.all[G.currentIndex][1]==false){
        G.all[G.currentIndex][1]=true;//更新当前题目已做的标记
        G.quesData[ G.list[G.currentList[G.currentIndex][0]].type ][2] +=1;//更新当前类型题目的做题量
    }
    if(flag)
    {
        getEbyId("divAns").innerHTML = "答对了！";
        ComboUpdate(true);
        if(G.nextQ){next();}
    }
    else
    {
        getEbyId("divAns").innerHTML = "误入歧途！";
        addToErrList(G.currentList[G.currentIndex][0]);
        ComboUpdate(false);
    }
    if(G.effects){showEffects();}//如果启用特效
}
//“答案”按钮的函数实现-->
function viewAns()
{
    var ty=G.list[G.currentList[G.currentIndex][0]].type;
    if(ty==1)
    {
        getEbyId("divAns").innerHTML = "答案: " + String.fromCharCode(G.ansidlist[G.list[G.currentList[G.currentIndex][0]].ans[0]-1]+65)+"<br />"+G.list[G.currentList[G.currentIndex][0]].explain;
    }
    else if (ty== 2 ||ty== 4)//多选、不定项答案显示
    {
        getEbyId("divAns").innerHTML = "答案: ";
        var choiceslen = G.currentoptioncount;
        Message(choiceslen);
        var ansflaglist = [choiceslen];
        for (var i =0;i < choiceslen;i++)//初始化标记数组
        {ansflaglist.push(false);}
        for (var i =0;i < G.list[G.currentList[G.currentIndex][0]].ans.length;i++)//正确的选项对应标志重置为true
        {ansflaglist[ G.list[G.currentList[G.currentIndex][0]].ans[i]-1 ]=true;}
        var ansid=0;
        while( ansid < choiceslen)
        {
            if( ansflaglist [G.randomlist[ansid]]==true){getEbyId("divAns").innerHTML +=String.fromCharCode(ansid+65) +' ';}
            ansid+=1;
        }
        getEbyId("divAns").innerHTML+="<br />"+G.list[G.currentList[G.currentIndex][0]].explain;
    }
    else if(ty== 6)//排序题的答案显示
    {
        var ansstr = "答案: ";
        for(var j =0;j<G.list[G.currentList[G.currentIndex][0]].ans.length;j++)
        {ansstr+=String.fromCharCode( G.ansidlist[ G.list[G.currentList[G.currentIndex][0]].ans[j]-1 ]+65 )+" ";}
        getEbyId("divAns").innerHTML = ansstr ;
    }
    else if(ty==7|| ty==8){
        var ansstr = "答案: "+G.list[G.currentList[G.currentIndex][0]]["ans"];
        getEbyId("divAns").innerHTML = ansstr ;
    }
    else
    {getEbyId("divAns").innerHTML = "答案: "+G.list[G.currentList[G.currentIndex][0]].ans;}
}

//“跳转”按钮的函数实现-->
function GoTo()
{
    num = getEbyId("txtNum").value;
    if (num <= G.currentList.length && num > 0)
    {
        G.currentIndex = num - 1;
        showQues();
    }
    else
    {Message("无题可做","green");}
}
//暂停计时
function PauseTest()
{
    if(G.InTest==true)
    {
        G.InTest=false;
        //更改按钮字样为“继续”-->
        getEbyId("Pause").innerHTML = "继续(R)";
        getEbyId("Ans").disabled = true;
    }
    else
    {
        //设置状态为考试中-->
        G.InTest=true;
        //更改按钮字样为“暂停”-->
        getEbyId("Pause").innerHTML = "暂停(R)";
        getEbyId("Ans").disabled = false;
    }
    showQues();
}
//键盘反馈-->
function KeyEvent(event)
{
    Message("","green");
    switch(event.keyCode)
    {
        case 37:case 90://上一题
            previous();
            break;
        case 39:case 86://下一题
            next();
            break;
        case 81://调用错题本
            showErrList();
            break;
        case 82:
            PauseTest();
            break;
        case 83:
            checkAns();
            break;
        case 84://错题本导出 T
            makeErrDownload();
            break;
        case 88:
            viewAns();
            break;
        case 87:
            showAll();
            break;
        default:
            break;
    }
    var keycode = event.keyCode;
    if(keycode >64 && keycode < (G.currentoptioncount+65) )
    {
        switch (G.list[G.currentList[G.currentIndex][0]].type)
        {
            case 1:case 2:case 4:case 6:
                ansClicked( G.randomlist[keycode-65]);
                break;
            case 3:
                ansClicked(keycode-65);
                break;
            default:
                break;
        }
    }
}

function UpdateTime()
{
    if(G.InTest)
    {
        var TimeStr = "";
        if( ++G.Second==60)
        {
            if(++G.Minute==60)
            {   
                G.Hour+=1;
                G.Minute=0;
            }
            G.Second=0;
        }
        TimeStr += G.Hour<10?"0"+G.Hour:G.Hour;
        TimeStr += ":";
        TimeStr += G.Minute<10?"0"+G.Minute:G.Minute;
        TimeStr += ":";
        TimeStr += G.Second<10?"0"+G.Second:G.Second;
        getEbyId("Timer").innerHTML = TimeStr;
    }
    
}
//隐藏/显示面板
function show_divRightTop(){
    var d=getEbyId("div_1");
    var b=getEbyId("btn_ImportArea");
    if(d.style.display!="none"){d.style.display="none";b.innerHTML="显示面板";}
    else{d.style.display="block";b.innerHTML="隐藏面板";}
}

/*xlsx.ext*/
function stringToXML(xmlString){
    var xmlDoc;
    //解析 xmlDoc
    if (!!window.ActiveXObject || "ActiveXObject" in window) {
        xmlDoc = new ActiveXObject('Microsoft.XMLDOM');//IE浏览器
        xmlDoc.async = false;//设置同步读取，保证文件完整加载
        xmlDoc.loadXML(xmlString);//读取文件
    }
    else{
        var parser=new DOMParser();
        xmlDoc=parser.parseFromString(xmlString,"text/xml");
    }
    return xmlDoc;
}

//从字符表示的列编号转为数字序号；A对应1
function getCol_StrToNum(str){
    var col=0;
    var end = str.length-1;
    for( var p = end; p >=0 ;p--){
        col+= ( str.charCodeAt( p )-64) * Math.pow(26 , end-p );
    }
    return col;
}

//从字符串解析表格坐标，返回 [坐标的行编号，坐标列的数字编号，原始列编号字符]
function parseRow_Col(colChars){
    if( typeof(colChars) != "string"){return [0,0];}
    else{
        var pattern = /[A-Z]/;
        var p = 0;
        while(p< colChars.length){
            if( pattern.exec(colChars.charAt(p) ) ){p+=1;continue;}//如果p位是字母，继续前进
            else{break;}//否则，跳出循环
        }
        return [ parseInt(colChars.substring(p , colChars.length) ), getCol_StrToNum( colChars.substring(0,p) ) , colChars.substring(0,p) ];
    }
}

//从数字列编号转为字符列编号，1对应A，27对应AA，……
function getCol_numToStr(num){
    if(num<0){return "";}
    var n = num;
    var r = 0;
    var str = "";
    while(n > 0){
        r=n%26;
        n=Math.floor(n/26);
        if(r==0){str="Z"+str;  n=n-1;}
        else{str = String.fromCharCode(r+64)+str ;}//余数+64得到ASCII码，随后转为字符，更新到r
    }
    return str;
}

//输出手机端题库
function mobileExam(){
    var Str='<!DOCTYPE HTML><HTML><head><TITLE>Combo 0</TITLE><meta http-equiv="content-type" content="text/html;charset=utf-8"><style type="text/css">body {font-size:36px;}a, a:visited{text-decoration:none; color:black}button{font-size:36px;}</style></head><body onkeyup="KeyEvent(event)"><div><button id="btnErrList" type="button" onclick="showErrList()">错题本(Q)</button><text >&nbsp;</text><button id="btnShowAll" type="button" onclick="showAll()">全部(W)</button><text >&nbsp;</text><text id="Timer" onload="UpdateTime()">00:00:00</text><text >&nbsp;</text><button id="Pause" type="button" onclick="PauseTest()">开始(R)</button><text >&nbsp;</text><button id="ExportErr" type="button" onclick="makeErrDownload()">导出错题(T)</button><div id="divQues" style="font-weight:bold;"></div><div id="divChoice"></div><div><span id="divAns" style="font-weight:bold;color:red;height:50px;"></span><text >&nbsp;</text><span id="divNotes" style="font-weight:bold;color:red;height:50px;"></span></div><br></br><button id="PrevQues" type="button" onclick="previous()">上题(Z)</button><text >&nbsp;</text><button id="btnSubmit" type="button" onclick="checkAns()">提交(S)</button><text >&nbsp;</text><button id="Ans" type="button" onclick="viewAns()">答案(X)</button><text >&nbsp;</text><button id ="NextQues" type="button" onclick="next()">下题(V)</button><br></br>第<input type="number" id="txtNum" style="font-size:24px;width:260px"></input>题<text >&nbsp;</text><button type="button" onclick="GoTo()">跳转</button></div></body><script type="text/javascript">var list=[';
    for(var i=0;i<G.list.length;i++){
        Str+=JSON.stringify(G.list[i]);
        if(i<G.list.length-1){Str+=",";}
    }
    Str+="];var InTest = false;var all = [];var allListIndex = 0;var errList = [];var errListIndex = 0;var currentList = all;var currentIndex = 0;var Combo = 0;var lastComboIndex = -1;for (var i = 0; i < list.length; ++i){all.push(i);}";
    Str+="function Message(msg,clr=\"red\"){document.getElementById(\"divNotes\").innerHTML =msg;document.getElementById(\"divNotes\").style.color=clr;}";
    Str+="function ComboUpdate(value){if (value == true ){if( currentIndex > lastComboIndex ){Combo+=1;lastComboIndex = currentIndex;}}else{Combo=0;}document.title=\"Combo \"+ Combo.toString();}";
    Str+="function previous(){if (currentIndex != 0){Message(\"\",\"white\");currentIndex--;if(InTest==false){PauseTest();}else{showQues();}}else {Message(\"第一个了！\",\"red\");}}";
    Str+="function next(){if (currentIndex < currentList.length - 1){Message(\"\",\"white\");currentIndex++;if(InTest==false){PauseTest();}else{showQues();}}else {Message(\"最后一个了！\",\"red\");}}";
    Str+="var choicelistlength = 10;var randomlist = new Array(choicelistlength);var flaglist = new Array(choicelistlength);var ansidlist = new Array(choicelistlength);var chosedlist = new Array(choicelistlength);var currentoptioncount=0;for (var i = 0;i < choicelistlength;i+=1){randomlist[i]=0;flaglist[i]=false;ansidlist[i]=0;chosedlist[i]=false;}";
    Str+="function makeErrDownload(){if( errList.length == 0){Message(\"没有错题，啥都不给\",\"gray\");return;}else{var errlistStr=\"\";for (var i = 0;i < errList.length;){errlistStr += (errList[i]+1).toString();i+=1;if(i<errList.length){errlistStr+=\" \";}}var dllink='<a href=\"data:text/plain,'+errlistStr+'\" download=\"ErrList.txt\">点此下载错题</a>';Message(dllink,\"#FF0\");}}";
    Str+="function showQues() {  if(InTest==true)  {if(currentList==all){ allListIndex = currentIndex; }else{ errListIndex = currentIndex; }Message(\"\",\"red\");document.getElementById(\"divAns\").innerHTML = \"\";document.getElementById(\"Ans\").disabled = false;var parts = list[currentList[currentIndex]].Ques.split(\"\t\");var question = parts[0];if (list[currentList[currentIndex]].type == 1 || list[currentList[currentIndex]].type==2 || list[currentList[currentIndex]].type==4 || list[currentList[currentIndex]].type==6){ currentoptioncount = parts.length - 1;for (var i = 0;i < choicelistlength;i+=1) {  randomlist[i]=choicelistlength;  flaglist[i] = false;  ansidlist[i] = 0;  chosedlist[i] = false; } var rdlstid = 0; while( rdlstid<currentoptioncount) {  var curNum = Math.floor(Math.random()*currentoptioncount);  if(curNum<currentoptioncount && flaglist[curNum]==false)  {flaglist[curNum] = true;ansidlist[curNum] = rdlstid;randomlist[ rdlstid ]=curNum;rdlstid+=1;  } } if (list[currentList[currentIndex]].type == 1){  document.getElementById(\"btnSubmit\").disabled = true; document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [单选]\" + question;  var choice = document.getElementById(\"divChoice\");  choice.innerHTML = \"\";  for (var i = 0; i < currentoptioncount; ++i)  {choice.innerHTML += '<a href=\"#\" onclick=\"ansClicked(' + randomlist[i] + ')\"> (' + String.fromCharCode(i+65)+') '+ parts[ randomlist[i]+1 ] + \"</a><br /><br/>\";  } } else{var choice = document.getElementById(\"divChoice\");choice.innerHTML = \"\";for (var i = 0; i < currentoptioncount; ++i){choice.innerHTML += '<span onclick=\"ansClicked(' + randomlist[i] + ')\"><label style=\"display:none;\"></label><a id=\"Choice'+randomlist[i] +'\" href=\"#\">(' + String.fromCharCode(i+65)+')' + parts[ randomlist[i]+1 ] + \"</a></span><br /><br/>\";}if (list[currentList[currentIndex]].type == 2){document.getElementById(\"btnSubmit\").disabled = false;document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [多选]\" + question;}else if (list[currentList[currentIndex]].type == 4){document.getElementById(\"btnSubmit\").disabled = false;document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [不定项]\" + question;}else if (list[currentList[currentIndex]].type == 6){document.getElementById(\"btnSubmit\").disabled = false;document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [排序]\" + question;choice.innerHTML+='<a id=\"fill_sort\" style=\"width:300px\" />';}}}else if (list[currentList[currentIndex]].type == 3){ currentoptioncount = 2; document.getElementById(\"btnSubmit\").disabled = true; document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [判断]\" + question; var choice = document.getElementById(\"divChoice\"); choice.innerHTML = \"\"; choice.innerHTML += '<a href=\"#\" onclick=\"ansClicked(0)\">(A) 正确</a><br /><br/>'; choice.innerHTML += '<a href=\"#\" onclick=\"ansClicked(1)\">(B) 错误</a><br /><br/>';}else if (list[currentList[currentIndex]].type == 5){document.getElementById(\"btnSubmit\").disabled = false;document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [填空]\" + question;var choice = document.getElementById(\"divChoice\");choice.innerHTML = \"\";choice.innerHTML+='<input type=\"text\" id=\"fill_empty\" style=\"width:300px\" />';}else if (list[currentList[currentIndex]].type == 7){ document.getElementById(\"btnSubmit\").disabled = true; document.getElementById(\"divQues\").innerHTML = (currentList[currentIndex] + 1) + \". [论述]\" + question;var choice = document.getElementById(\"divChoice\");choice.innerHTML = \"\";choice.innerHTML+='<input type=\"text\" id=\"fill_essay\" style=\"width:300px\" />';}  }  else  {document.getElementById(\"Ans\").disabled = true;document.getElementById(\"divAns\").innerHTML = \"\";document.getElementById(\"divQues\").innerHTML = \" 暂停计时，请点击“开始”/“继续”按钮，继续测试 \";document.getElementById(\"divChoice\").innerHTML = \"\";  } }";
    Str+="function addToErrList(index){var isFound = 10;for (var i = 0; i < errList.length; ++i){if (errList[i] == index){isFound = 1;break;}}if (isFound == 10){errList.push(index);document.getElementById(\"btnErrList\").innerHTML = \"错题本(Q) \" + errList.length + \" \";}}";
    Str+="function showErrList(){if (errList.length > 0) {currentList = errList;currentIndex = errListIndex;showQues();}else{ Message(\"万无一失\",\"green\"); }}";
    Str+="function showAll(){if (all.length > 0) {currentList = all;currentIndex = allListIndex;showQues();}else{Message(\"空无一物\",\"green\");}}";
    Str+="function checkAns(){var choices = document.getElementById(\"divChoice\").children;var correct = false;if (list[currentList[currentIndex]].type == 2 || list[currentList[currentIndex]].type == 4){var ansValue = 0;var choicesValue = 0;var anslen = list[currentList[currentIndex]].ans.length;var tmpstr=\"\";for (var i = 0;i<anslen;i++){ansValue +=Math.pow(2, list[currentList[currentIndex]].ans[i]);}for (var i = 0; i < choices.length; i++){if (randomlist[i]<choices.length && chosedlist[ randomlist[i] ]== true){choicesValue += Math.pow(2,randomlist[i]+1);tmpstr+=(randomlist[i]).toString()+\" \";}}if(ansValue == choicesValue){correct = true;}}else if(list[currentList[currentIndex]].type == 5){var fill_ans = document.getElementById(\"fill_empty\").value ;var fill_ans_list = fill_ans.split(\" \");var fill_correct_count=0;for(var i = 0;i<fill_ans_list.length;i++){if( list[currentList[currentIndex]].ans[0].match( fill_ans_list[i] ) ){fill_correct_count+=1;}else{break;}}if( fill_correct_count == fill_ans_list.length){correct = true;}}else if(list[currentList[currentIndex]].type == 6){var fill = document.getElementById(\"fill_sort\").text;if(fill.length != list[currentList[currentIndex]].ans.length){correct=false;}else{var ans_ptr = 0;for(var j = 0;j<fill.length && ans_ptr<list[currentList[currentIndex]].ans.length;j++){if( fill[j] != String.fromCharCode( ansidlist[list[currentList[currentIndex]].ans[j]-1]+65 ) ){break;}else{ans_ptr+=1;}}if(ans_ptr == list[currentList[currentIndex]].ans.length){correct = true;}}}showAnsInfo(correct);}";
    Str+="function ansClicked(origin_id){if (list[currentList[currentIndex]].type == 2 || list[currentList[currentIndex]].type == 4){var curChoiceId = \"Choice\"+origin_id.toString();if (document.getElementById(curChoiceId).style.color != \"red\"){document.getElementById(curChoiceId).style.color = \"red\";chosedlist[origin_id]=true;}else {document.getElementById(curChoiceId).style.color = \"black\";chosedlist[origin_id]=false;}}else if (list[currentList[currentIndex]].type == 1){showAnsInfo(list[currentList[currentIndex]].ans[0] == origin_id+1);}else if(list[currentList[currentIndex]].type == 3){showAnsInfo(list[currentList[currentIndex]].ans[0] == origin_id+1);}else if(list[currentList[currentIndex]].type == 6){document.getElementById(\"fill_sort\").innerHTML+=String.fromCharCode( ansidlist[origin_id]+65);}}";
    Str+="function showAnsInfo(flag){if(flag){document.getElementById(\"divAns\").innerHTML = \"答对了！\";ComboUpdate(true);next();}else{document.getElementById(\"divAns\").innerHTML = \"误入歧途！\";addToErrList(currentList[currentIndex]);ComboUpdate(false);}}";
    Str+="function viewAns(){if(list[currentList[currentIndex]].type == 1){document.getElementById(\"divAns\").innerHTML = \"答案: \" + String.fromCharCode( ansidlist[list[currentList[currentIndex]].ans[0]-1]+65)+\"<br />\"+list[currentList[currentIndex]].explain;}else if (list[currentList[currentIndex]].type == 2 || list[currentList[currentIndex]].type == 4){document.getElementById(\"divAns\").innerHTML = \"答案: \";var choiceslen = currentoptioncount;var ansflaglist = [choiceslen];for (var i =0;i < choiceslen;i++){ansflaglist.push(false);}for (var i =0;i < list[currentList[currentIndex]].ans.length;i++){ansflaglist[ list[currentList[currentIndex]].ans[i]-1 ]=true;}var ansid=0;while( ansid < choiceslen){if( ansflaglist [randomlist[ansid]]==true){document.getElementById(\"divAns\").innerHTML +=String.fromCharCode(ansid+65) +' ';}ansid+=1;}document.getElementById(\"divAns\").innerHTML+=\"<br />\"+list[currentList[currentIndex]].explain;}else if(list[currentList[currentIndex]].type == 6){var ansstr = \"答案: \";for(var j =0;j<list[currentList[currentIndex]].ans.length;j++){ansstr+=String.fromCharCode( ansidlist[ list[currentList[currentIndex]].ans[j]-1 ]+65 )+\" \";}document.getElementById(\"divAns\").innerHTML = ansstr ;}else{document.getElementById(\"divAns\").innerHTML = \"答案: \"+list[currentList[currentIndex]].ans;}}";
    
    Str+="function GoTo(){num = document.getElementById(\"txtNum\").value;if (num <= currentList.length && num > 0){currentIndex = num - 1;showQues();}else{Message(\"无题可做\",\"green\");}}";
    
    Str+="function PauseTest(){if(InTest==true){InTest=false;document.getElementById(\"Pause\").innerHTML = \"继续(R)\";document.getElementById(\"Ans\").disabled = true;}else{InTest=true;document.getElementById(\"Pause\").innerHTML = \"暂停(R)\";document.getElementById(\"Ans\").disabled = false;}showQues();}";
    
    Str+="function KeyEvent(event){Message(\"\",\"green\");switch(event.keyCode){case 37:case 90:previous();break;case 39:case 86:next();break;case 81:showErrList();break;case 82:PauseTest();break;case 83:checkAns();break;case 84:makeErrDownload();break;case 88:viewAns();break;case 87:showAll();break;default:break;}var keycode = event.keyCode;if(keycode >64 && keycode < (currentoptioncount+65) ){switch (list[currentList[currentIndex]].type){case 1:case 2:case 4:case 6:ansClicked( randomlist[keycode-65]);break;case 3:ansClicked(keycode-65);break;default:break;}}}";
    
    Str+="var Hour = 0;var Minute = 0;var Second = 0;";
    Str+="function UpdateTime(){if(InTest){TimeStr = \"\";if( ++Second==60){if(++Minute==60){   Hour+=1;Minute=0;}Second=0;}TimeStr += Hour<10?\"0\"+Hour:Hour;TimeStr += \":\";TimeStr += Minute<10?\"0\"+Minute:Minute;TimeStr += \":\";TimeStr += Second<10?\"0\"+Second:Second;document.getElementById(\"Timer\").innerHTML = TimeStr;}}";
    
    Str+="setInterval(UpdateTime,1000);document.getElementById(\"btnShowAll\").innerHTML = \"全部(W)\t\" + list.length + \" 题\";showQues();document.getElementById(\"Ans\").disabled = true;document.getElementById(\"divChoice\").disabled=true;</script></HTML>";
    
    var e=document.getElementById("mobileExamText");
    e.style.display="block";
    e.innerHTML=Str;
}